package com.eqdd.yiqidian.utils;

import android.content.Context;
import android.util.TypedValue;

import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.header.MaterialHeader;

/**
 * Created by lvzhihao on 17-8-2.
 */

public class MVCRefreshUtil {
    public static void setUtrlRefreshHeader(Context context, PtrClassicFrameLayout ptrFrameLayout) {
        MaterialHeader header = new MaterialHeader(context);
        header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
        header.setPadding(0, dipToPix(context, 15), 0, dipToPix(context, 10));
        header.setPtrFrameLayout(ptrFrameLayout);
        ptrFrameLayout.setLoadingMinTime(800);
        ptrFrameLayout.setDurationToCloseHeader(800);
        ptrFrameLayout.setHeaderView(header);
        ptrFrameLayout.addPtrUIHandler(header);
    }

    public static int dipToPix(Context context, int dip) {
        int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, context.getResources().getDisplayMetrics());
        return size;
    }
}
